package com.itheima.reggie.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CategoryMapper extends BaseMapper<Category> {

    //查询菜品或者套餐是否存在
    @Select("SELECT sum(a.count) AS sums FROM ( SELECT count(1) AS count FROM dish d where d.category_id = #{id} UNION SELECT count(1) AS count FROM setmeal s where s.category_id = #{id} ) a")
    public Integer getDishOrSetmealIsexist(@Param("id") Long id);

    @Select("SELECT count(a.id) AS `value`, b.`name` FROM dish a INNER JOIN category b ON a.category_id = b.id GROUP BY a.category_id")
    public List<JSONObject> selectAnalysis();
}
